<?php

class DataBase {
	
	private $host;
	private $user;
	private $pass;
	private $name;
	private $prefix;
	var $dbId;
	
	function __construct ($h, $n, $u, $p) {
		$this->host = $h;
		$this->user = $u;
		$this->pass = $p;
		$this->name = $n;
	}
	
	function getPrefix() {
		return $this->prefix;
	}
	
	function setPrefix($prefix) {
		$this->prefix = $prefix;
	}
	
	function connect() {
		$this->dbId = mysql_connect ($this->host, $this->user, $this->pass); 
		mysql_select_db ($this->name, $this->dbId);
		mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'", $this->dbId);
	}
	
	function disconnect() {
		mysql_close($this->$dbId);
	}
	
	function query($sql) {
		$r = mysql_query ($sql, $this->dbId);
		
		$queryType = substr($sql, 0, strpos($sql, ' '));
		if ($queryType == 'SELECT') {
			
			$arrResult = array();
			while ($res = mysql_fetch_array($r)) {
				$arrResult[] = $res;
			}
			return $arrResult;	
		
		} else {
			return $r;
		}
	}
	
}
?>